package part1.language_basis.day06.day06test;

import java.util.Arrays;

public class MaxOfArray {
    public static void main(String[] args) {

        say();
        sayHi("zhangsan");
        sayHello("lisi",34);
        sayHello("wangwu",55);

        double b = getNum();
        System.out.println(b);

        int m=4,n=5;
        int c = plus(m,n);
        System.out.println(c);

        int[] d = testArray(4,100);
        System.out.println(Arrays.toString(d));
        System.out.println("数组的长度为："+d.length);
        int[] e = testArray(4,20);
        for (int i = 0; i < e.length; i++) {
            System.out.println(e[i]);
        }


        /*
        //声明数组并填充
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random()*100);
            System.out.println(arr[i]);
        }
        //找数组最大值
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i]>max){
                max = arr[i];
            }
        }
        //数组扩容并将最大值放到最后一个元素
        arr = Arrays.copyOf(arr,arr.length+1);
        arr[arr.length-1] = max;
        System.out.println(Arrays.toString(arr));

         */
    }


    public static void say(){
        System.out.println("大家好，我叫wkj，今年39岁了");
    }

    public static void sayHi(String name){
        System.out.println("大家好，我叫"+name+",今年39岁了");
    }

    public static void sayHello(String name,int age){
        if (age>50){
            return;
        }
        System.out.println("大家好，我叫"+name+",今年"+age+"岁了");
    }

    public static double getNum(){
        return 8.8;
    }

    public static int plus(int num1,int num2){
        return num1+num2;
    }

    public static int[] testArray(int len,int max){
        int[] arr = new int[len];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random()*(max+1));
        }
        //冒泡排序
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if (arr[j]>arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
        return arr;
    }
}
